<?php

// 查看一个竞秀活动的前十名照片。
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

require_once libfile('function/database');
require_once libfile('function/vote');

$aid = intval(getgpc('aid'));
if (empty($aid)) {
	exit();
}
// 当前页
$page = intval(getgpc('page'));
if(empty($page)) {
	$page = 1;
}
$pagesize = intval(getgpc('pagesize'));
if(empty($pagesize)) {
	$pagesize = 12;
}

$sql = ' select count(*) as user_count from '.DB::table('vote_user').' where aid = '.$aid;
$row = DB::fetch_first($sql);
$user_count = $row['user_count'];

$pages = get_pages($user_count, $page, $pagesize);

$start = ($page-1) * $pagesize;
$end = $page * $pagesize;

$activity = get_activity($aid);
$total_score = build_total_score_sql($activity['credits_rule']);
$rank_sql = ' select  '.$total_score.' as total_score, uc.* from '.DB::table('vote_user_count').' uc ';
$sql = ' select @rownum := @rownum + 1 as rank, a.* from ( '.$rank_sql.' ) a,(select @rownum := 0) r
		where a.aid = '.$aid.' order by a.total_score desc limit '."$start, $end";

$users = query($sql);
get_vote_user($users);
get_user_pic($users);

include_once template("bid/view");
?>